package frontera;

import entidad.Transferencia;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;
import java.util.Date;

public class GenerarReportes extends javax.swing.JPanel {

    private VentanaPrincipal ventanaP;
    
    public GenerarReportes(VentanaPrincipal v) {
        initComponents();
        this.ventanaP = v;
                
        llenaCalendario();
        Date now = new Date();
        yearCBH.setSelectedItem(now.getYear());
        mesCBH.setSelectedItem(now.getMonth());
        diaCBH.setSelectedItem(now.getDate()+1);
        actualizarResultados();
    }

    public void actualizarResultados(){
        
//        Date inicio = Date.parse((diaCBD.getSelectedItem().toString()).
//                concat(mesCBD.getSelectedItem().toString()).
//                concat(yearCBD.getSelectedItem().toString()),
//                          DateFormat.forPattern("ddMMyyyy"));
//        Date fin = Date.parse((diaCBH.getSelectedItem().toString()).
//                concat(mesCBH.getSelectedItem().toString()).
//                concat(yearCBH.getSelectedItem().toString()),
//                          DateFormat.forPattern("ddMMyyyy"));
        Date inicio = new Date((int)yearCBD.getSelectedItem(), (int)mesCBD.getSelectedItem(), (int)diaCBD.getSelectedItem());
        Date fin    = new Date((int)yearCBH.getSelectedItem(), (int)mesCBH.getSelectedItem(), (int)diaCBH.getSelectedItem());
                
        ArrayList<Transferencia> transferencias = VentanaPrincipal.controlTransferencia.buscar(inicio, fin,
                                                            cargaCK.isSelected(),
                                                            descargaCK.isSelected(),
                                                            devolucionCK.isSelected());
        
        String[] cols = {"Fecha", "Producto", "Lote", "Cantidad", "Motivo", "Descripción"};
        
        DefaultTableModel modelo = new DefaultTableModel(cols, 0);
        for(Transferencia t : transferencias) modelo.addRow(t.toArray());
        resultados.setModel(modelo);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sp = new javax.swing.JScrollPane();
        resultados = new javax.swing.JTable();
        titulo = new javax.swing.JLabel();
        imagen = new javax.swing.JLabel();
        diaCBD = new javax.swing.JComboBox();
        mesCBD = new javax.swing.JComboBox();
        yearCBD = new javax.swing.JComboBox();
        diaCBH = new javax.swing.JComboBox();
        mesCBH = new javax.swing.JComboBox();
        yearCBH = new javax.swing.JComboBox();
        cargaCK = new javax.swing.JCheckBox();
        devolucionCK = new javax.swing.JCheckBox();
        descargaCK = new javax.swing.JCheckBox();
        desdeL = new javax.swing.JLabel();
        hastaL = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(51, 0, 102)));

        resultados.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N
        resultados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null}
            },
            new String [] {
                "Fecha", "Producto", "Lote", "Cantidad", "Motivo", "Descripción"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        sp.setViewportView(resultados);

        titulo.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
        titulo.setForeground(new java.awt.Color(102, 0, 204));
        titulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titulo.setText("Reportes");

        imagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icono2.png"))); // NOI18N

        diaCBD.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        diaCBD.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        diaCBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                diaCBDActionPerformed(evt);
            }
        });

        mesCBD.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        mesCBD.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
        mesCBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mesCBDActionPerformed(evt);
            }
        });

        yearCBD.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        yearCBD.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2013", "2014" }));
        yearCBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yearCBDActionPerformed(evt);
            }
        });

        diaCBH.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        diaCBH.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        diaCBH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                diaCBHActionPerformed(evt);
            }
        });

        mesCBH.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        mesCBH.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
        mesCBH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mesCBHActionPerformed(evt);
            }
        });

        yearCBH.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        yearCBH.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2013", "2014" }));
        yearCBH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yearCBHActionPerformed(evt);
            }
        });

        cargaCK.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        cargaCK.setSelected(true);
        cargaCK.setText(Transferencia.carga);
        cargaCK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cargaCKActionPerformed(evt);
            }
        });

        devolucionCK.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        devolucionCK.setSelected(true);
        devolucionCK.setText(Transferencia.devolucion);
        devolucionCK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                devolucionCKActionPerformed(evt);
            }
        });

        descargaCK.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        descargaCK.setSelected(true);
        descargaCK.setText(Transferencia.descarga);
        descargaCK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                descargaCKActionPerformed(evt);
            }
        });

        desdeL.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        desdeL.setText("Desde");

        hastaL.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        hastaL.setText("Hasta");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(titulo, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(imagen))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(desdeL, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                            .addComponent(hastaL, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(diaCBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mesCBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(yearCBD, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(diaCBH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mesCBH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(yearCBH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cargaCK)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(descargaCK)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(devolucionCK)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(imagen)
                    .addComponent(titulo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(diaCBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mesCBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(yearCBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(desdeL))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(diaCBH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mesCBH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(yearCBH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cargaCK)
                        .addComponent(descargaCK)
                        .addComponent(devolucionCK))
                    .addComponent(hastaL))
                .addGap(18, 18, 18)
                .addComponent(sp, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cargaCKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cargaCKActionPerformed
        actualizarResultados();
    }//GEN-LAST:event_cargaCKActionPerformed

    private void descargaCKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_descargaCKActionPerformed
        actualizarResultados();
    }//GEN-LAST:event_descargaCKActionPerformed

    private void devolucionCKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_devolucionCKActionPerformed
        actualizarResultados();
    }//GEN-LAST:event_devolucionCKActionPerformed

    private void diaCBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diaCBDActionPerformed
        actualizarResultados();
    }//GEN-LAST:event_diaCBDActionPerformed

    private void mesCBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mesCBDActionPerformed
        actualizarResultados();
    }//GEN-LAST:event_mesCBDActionPerformed

    private void yearCBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearCBDActionPerformed
        actualizarResultados();
    }//GEN-LAST:event_yearCBDActionPerformed

    private void diaCBHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diaCBHActionPerformed
        actualizarResultados();
    }//GEN-LAST:event_diaCBHActionPerformed

    private void mesCBHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mesCBHActionPerformed
        actualizarResultados();
    }//GEN-LAST:event_mesCBHActionPerformed

    private void yearCBHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearCBHActionPerformed
        actualizarResultados();
    }//GEN-LAST:event_yearCBHActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox cargaCK;
    private javax.swing.JCheckBox descargaCK;
    private javax.swing.JLabel desdeL;
    private javax.swing.JCheckBox devolucionCK;
    private javax.swing.JComboBox diaCBD;
    private javax.swing.JComboBox diaCBH;
    private javax.swing.JLabel hastaL;
    private javax.swing.JLabel imagen;
    private javax.swing.JComboBox mesCBD;
    private javax.swing.JComboBox mesCBH;
    private javax.swing.JTable resultados;
    private javax.swing.JScrollPane sp;
    private javax.swing.JLabel titulo;
    private javax.swing.JComboBox yearCBD;
    private javax.swing.JComboBox yearCBH;
    // End of variables declaration//GEN-END:variables

    private void llenaCalendario() {
        ArrayList<Integer> year = new ArrayList<>();
        ArrayList<Integer> mes = new ArrayList<>();
        ArrayList<Integer> dia = new ArrayList<>();
        for(int i=1; i <32;i++)dia.add(i);
        for(int j=1; j <13;j++)mes.add(j);
        for(int h=2012; h <2021;h++)year.add(h);
        yearCBD.setModel(new DefaultComboBoxModel(year.toArray()));
        yearCBH.setModel(new DefaultComboBoxModel(year.toArray()));
        mesCBD.setModel(new DefaultComboBoxModel(mes.toArray()));
        mesCBH.setModel(new DefaultComboBoxModel(mes.toArray()));
        diaCBD.setModel(new DefaultComboBoxModel(dia.toArray()));
        diaCBH.setModel(new DefaultComboBoxModel(dia.toArray()));
    }
}
